import React, { Component } from 'react'

import qs from 'querystring'

// 初始化数据
const DetailData = [
     { id:'01',content:'你好，王珏' },   
     { id:'02',content:'你好，陈嘉丽' },   
     { id:'03',content:'你好，陈倩霞' }   
]

export default class Detail extends Component {
    
    render() {
        console.log(this.props.location)

        // params接收参数
        // const { title,id } = this.props.match.params

        // search接收参数
        const { search } = this.props.location.state
        const { id,title} = qs.parse(search.slice(1))

        // state接收参数
        // const { id,title } = this.props.location.state || {}
        
        const newDetailData = DetailData.find((detailObj) =>{
            return detailObj.id === id;
        })

        return (
            <div>
                <ul>
                    <li>id:{ id }</li>
                    <li>title:{ title }</li>
                    <li>content:{ newDetailData.content }</li>
                </ul>
            </div>
        )
    }
}
